package com.dream.libxrec.camera;

import android.content.Context;
import android.util.Size;

public abstract class ICamera {

    protected Context mContext;
    public String mCameraID = "0";//摄像头ID
    protected Size mCameraSize = null;
    protected int mRotation = 0;//旋转方向：0,90,180,270
    protected boolean isMirror = false;//画面是否镜像

    public static final int TYPE_I420 = 0;
    public static final int TYPE_NV12 = 1;
    public static final int TYPE_NV21 = 2;

    protected ImageAvailableListener mImageAvailableListener = null;

    public void init(Context ct, String cameraID, Size size,int rotation,boolean isMirror){
        this.mContext = ct;
        this.mCameraID = cameraID;
        this.mRotation = rotation;
        this.isMirror = isMirror;

        if (mRotation == 90||mRotation == 270){
            //如果需要旋转，则置换一下宽高
            this.mCameraSize = new Size(size.getHeight(),
                    size.getWidth());
        }else{
            this.mCameraSize = size;
        }
    }

    public abstract boolean isRun();
    public Size getSize(){
        return mCameraSize;
    }

    public abstract void start();
    public abstract void stop();

    public String getChannel(){
        return mCameraID;
    }

    /**
     * 添加YUV数据监听
     * @param listener
     */
    public void addListener(ImageAvailableListener listener){
        mImageAvailableListener = listener;
    }

    /**
     * 设置帧率
     * @param fps
     */
    public abstract void setFps(int fps);

    public static interface ImageAvailableListener{
        public void onImageAvailable(String channel,byte[] data,int type,
                                     int width,
                                     int height);
    }

    public static ICamera build(){
        return new XCamera2();
    }
}
